package kt.com.bilin.coin.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kt.com.bilin.coin.api.ApiObserver
import kt.com.bilin.coin.api.ApiRequest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job

open class BaseViewModel : ViewModel() {
    var mCleared = false
//    fun <T> launchUI(
//        block: suspend CoroutineScope.() -> T, error: ((Throwable) -> Unit)? = null, complete: (() -> Unit)? = null, livedata: MutableLiveData<ApiProcess<T>>? = null
//    ) {
//        //ApiRequest(viewModelScope).launchUI(block, error, complete, livedata)
//    }

    fun <T> launchUI(
            block: suspend CoroutineScope.() -> T, apiObserver: ApiObserver<T>? = null, error: ((Throwable) -> Unit)? = null, complete: (() -> Unit)? = null
    ): Job = ApiRequest(viewModelScope).launchUI(block, error, complete, apiObserver)

    override fun onCleared() {
        super.onCleared()
        mCleared = true
    }

    fun isCleared() = mCleared
}